package com.njuse.jvmfinal.Instruction;

import java.nio.ByteBuffer;

import com.njuse.jvmfinal.Starter;
import com.njuse.jvmfinal.loading.loader;
import com.njuse.jvmfinal.memory.jclass.JClass;
import com.njuse.jvmfinal.runtimestructure.Jarray;
import com.njuse.jvmfinal.runtimestructure.Jframe;
import com.njuse.jvmfinal.runtimestructure.Jlink;

public class NEWARRAY extends Instruction {
	private int type;
	
	public  void readindex(ByteBuffer reader) {
		this.type=(int)reader.get();
	}
	
	public void execute(Jframe frame) {
		Object[] stack=frame.getManagestack();
		int top=frame.getStacktop();
		int count=(int)stack[top-1];
		top--;
		String name="";
	    switch (count) {
	    case 11:{name=name+"[J";
	        break;}	        
	    case 10:{name=name+"[I";
	        break;}
	    case 9:{name=name+"[S";
	        break;}
	    case 8:{name=name+"[D";
	        break;}
	    case 7:{name=name+"[F";
	        break;}
	    case 6: {name=name+"[C";
	        break;}
	    case 5:{name=name+"[Z";
	        break;}        
	    }
	    JClass arr=loader.getinstance().load(name, Starter.startcp, 1);
	    Jlink link=new Jlink(count,null);
        Jarray array=new Jarray(link,type,null,arr);
		stack[top]=array;
		top++;
		frame.setManagestack(stack);
		frame.setStacktop(top);
		
	}
}
